package org.thread.Homework04;/*
 *@Author: gjh
 *Date: 2025/3/12 8:08
 *Describe:
 */

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MainTest {
    private static Integer filmNum = 100;
    public final static MainTest mainTest = new MainTest();
    public static void main(String[] args) throws ExecutionException, InterruptedException {
       /* MyRunnable myRunnable = new MyRunnable("电影1");
        MyRunnable myRunnable1 = new MyRunnable("电影2");
        Thread thread = new Thread(myRunnable);
        Thread thread1 = new Thread(myRunnable1);
        thread.start();
        thread1.start();*/

        MyCallable mc = new MyCallable("电影1");
        MyCallable mc1 = new MyCallable("电影2");

        FutureTask<Integer> futureTask = new FutureTask<>(mc);
        FutureTask<Integer> futureTask1 = new FutureTask<>(mc1);

        Thread thread = new Thread(futureTask);
        Thread thread1 = new Thread(futureTask1);

        thread.start();
        thread1.start();

        System.out.println("卖出电影票：");
        System.out.println(futureTask.get()+futureTask1.get() - 2);
    }
    public synchronized Boolean sellFilmNum(){
        if(filmNum > 0){
            filmNum--;
            return true;
        }else{
            return false;
        }
    }
}
